package com.nullpointer.xchat.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class HistoryMessage {
	private MessageContent messageContent;
	private int unreadNum;
	private boolean isFriend;

	public boolean isFriend() {
		return isFriend;
	}

	public void setFriend(boolean isFriend) {
		this.isFriend = isFriend;
	}

	public MessageContent getMessageContent() {
		return messageContent;
	}

	public void setMessageContent(MessageContent messageContent) {
		this.messageContent = messageContent;
	}

	public int getUnreadNum() {
		return unreadNum;
	}

	public void setUnreadNum(int unreadNum) {
		this.unreadNum = unreadNum;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static HistoryMessage fromJsonToMessageHistory(String json) {
		return new JSONDeserializer<HistoryMessage>().use(null,
				HistoryMessage.class).deserialize(json);
	}

	public static String toJsonArray(Collection<HistoryMessage> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<HistoryMessage> fromJsonArrayToMessageHistorys(
			String json) {
		return new JSONDeserializer<List<HistoryMessage>>()
				.use(null, ArrayList.class).use("values", HistoryMessage.class)
				.deserialize(json);
	}

}
